package com.example.administrator.pomelostreet.fragment;


import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.pomelostreet.R;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class ShangXin_Fragment extends Fragment {
    private Context context;
    private TabLayout tabLayout;
    private String[] Navigation;
    private ViewPager viewPager;
    private List<Fragment> fragmentList;
    private NavigationAdapter adapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
         context = container.getContext();
        View view= inflater.inflate(R.layout.fragment_shang_xin_, container, false);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        init(view);
        initFragment();
        Navigation=getResources().getStringArray(R.array.TabNavigation);
        adapter=new NavigationAdapter(getChildFragmentManager());
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager,true);
        tabLayout.setTabTextColors(Color.BLACK,getResources().getColor(R.color.colorAccent));


    }

    private void initFragment() {
        fragmentList=new ArrayList<>();
        //女装界面
        FrockFragment frockFragment=new FrockFragment();
        //上新界面
        NewClothesFragment newclothesFragment=new NewClothesFragment();
        //鞋包界面
//        for(int i=1;i<6;i++){
//            ShoeBagFragment shoebagFragment=new ShoeBagFragment();
//
//            Bundle bundle=new Bundle();
//            bundle.putInt("index",i);
//            shoebagFragment.setArguments(bundle);
//        }

        ShoeBagFragment shoebagFragment=new ShoeBagFragment();
        //居家界面
        HomesFragment homesFragment=new HomesFragment();
        //母婴界面
        InfantMomFragment infantmomFragment=new InfantMomFragment();
        //美状界面
        MIXBOXFragment mixboxFragment=new MIXBOXFragment();

//        for(int i=1;i<6;i++){
//            FoodFragment foodFragment=new FoodFragment();;
//
//            Bundle bundle=new Bundle();
//            bundle.putInt("index",i);
//            shoebagFragment.setArguments(bundle);
//        }

        //美食界面
        FoodFragment foodFragment=new FoodFragment();


        //数码界面
        DigitalFragment digitalFragment=new DigitalFragment();
        //运动界面
        ExerciseFragment exerciseFragment=new ExerciseFragment();
        //图文界面
        ImageTextFragment imageTextFragment=new ImageTextFragment();
        fragmentList.add(frockFragment);
        fragmentList.add(newclothesFragment);
        fragmentList.add(shoebagFragment);
        fragmentList.add(homesFragment);
        fragmentList.add(infantmomFragment);
        fragmentList.add(mixboxFragment);
        fragmentList.add(foodFragment);
        fragmentList.add(digitalFragment);
        fragmentList.add(exerciseFragment);
        fragmentList.add(imageTextFragment);
    }

    private void init(View view) {
        viewPager= (ViewPager) view.findViewById(R.id.viewpager);
        tabLayout= (TabLayout) view.findViewById(R.id.tablayout);

    }



    public class NavigationAdapter extends FragmentPagerAdapter{

        public NavigationAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return Navigation[position];
        }
    }




}
